// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        lArrow:{
            default:null,
            type:cc.Node,
        },

        lArrowDis:{
            default:null,
            type:cc.Node
        },

        rArrow:{
            default:null,
            type:cc.Node
        },

        rArrowDis:{
            default:null,
            type:cc.Node
        },

        levelLabel:{
            default:null,
            type:cc.Label
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this._levels = [{name:"Practice",value:cc.gg.enumConfig.RoomMode.PRACTICE},
            {name:"Beginner",value:cc.gg.enumConfig.RoomMode.BEGINNER},
            {name:"Rookies",value:cc.gg.enumConfig.RoomMode.ROOKIES},
            {name:"Start",value:cc.gg.enumConfig.RoomMode.STARS},
            {name:"Amazing",value:cc.gg.enumConfig.RoomMode.AMAZING}]
        this._levelIdx = 0
        this.initLevelSelectState()
    },

    start () {

    },

    // update (dt) {},

    initLevelSelectState:function () {
        this.changeLevelState(0)
    },

    changeLevelState:function (idx) {
        cc.log("现在的idx是：",idx)
        if(idx === 0){
            this.lArrow.active = false
            this.lArrowDis.active = true
        }else if(idx === this._levels.length-1){
            this.rArrow.active = false
            this.rArrowDis.active = true
        }else {
            this.rArrow.active = true
            this.lArrow.active = true
        }

        this.levelLabel.string = this._levels[idx].name
        this._levelIdx = idx
    },

    onArrowClicked:function (event) {
        let btnName = event.target.name
        if(btnName === "LeftArrow"){
            this._levelIdx--
            this.changeLevelState(this._levelIdx)
        }else if(btnName === "RightArrow"){
            this._levelIdx++
            this.changeLevelState(this._levelIdx)
        }else {
            cc.error("这是不可能的")
        }
    },

    onLevelSelectorClose:function (event) {
        this.node.active = false
        this._levelIdx = 0
    },

    // async onPlayClicked (event) {
    //     await cc.gg.toastMgr.showNetWaitting()
    //     let gameId = this._levels[this._levelIdx].value || this._roomType || this._peopleCount
    //     cc.log("value：",this._levels[this._levelIdx].value)
    //     cc.log("this._roomType：",this._roomType)
    //     cc.log("this._peopleCount：",this._peopleCount)
    //     this.lobbyMgr._onFindRoom(this._gameType,gameId)
    // },

    initLevelSelector:function (lobbyMgr,gameType,peopleCount,gameRound) {
        cc.log("打开level selector,roomtype:",gameType,"  people count:",peopleCount)
        this._gameRound = gameRound
        this._peopleCount = peopleCount
        this._gameType = gameType
        this.lobbyMgr = lobbyMgr
    },
});
